CS5340 Lab2 report2

_learn_node_parameter_w()

When input is None

It means there are no observation of its parents. In this case weight size is 1, and weights[0] equals to the average of output using numpy.average().

Otherwise

Referring to the 𝐶 +1 equations in page 43 from the lec_6 ppt, these equations can be vectorized into:

where:

$\boldsymbol{w}_{(C+1)\times 1}$ is the unknown weights we need: $\boldsymbol{w} = {\begin{pmatrix}w_0,w_{u_1},…,w_{u_C}\end{pmatrix}}^T$
N is the number of observations of this node. C is the number of this node’s parents. $x_{u,n}$ is the $n^{th}$ observation of this node(output[n]).
We can use numpy.linalg.solve() to solve this equation to get the weights vector $\boldsymbol{w}$.

_learn_node_parameter_var()

Take the derivative of 𝐿 w.r.t to $\sigma ^ 2$ and equating to zero:

where:

_get_learned_parameters()

For each node, add the observations of its parents into the input array. Use _learn_node_parameter_w() to learn the weights $\boldsymbol{w}$, using this $\boldsymbol{w}$ and function _learn_node_parameter_var() to get the var $\hat{\sigma ^ 2}$, set $\hat{\sigma ^ 2}$ to be this node’s var, set $\boldsymbol{w}[0]$ to be this node’s bias, and for node’s $i^{th}$ parent set $\boldsymbol{w}[i]$ to be its weight.